package com.example.pathviewdemo.widget;


import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Region;

/**
 * 地图子类的绘制 对象。
 */
public class MapChildCanvas {
    Path path;// 路径
    int drawColor;// 绘制颜色
    String id;
    String cityName;

    public Path getPath() {
        return path;
    }

    public void setPath(Path path) {
        this.path = path;
    }

    public int getDrawColor() {
        return drawColor;
    }

    public void setDrawColor(int drawColor) {
        this.drawColor = drawColor;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public MapChildCanvas(Path path) {
        this.path = path;
    }

    public MapChildCanvas(Path path, int drawColor) {
        this.path = path;
        this.drawColor = drawColor;
    }

    /**
     *
     * @param canvas
     * @param paint 画笔对象 可以全局使用一个。
     * @param select
     */
    void onChildDraw(Canvas canvas,Paint paint,boolean select){
         if (select){
             paint.clearShadowLayer();
             paint.setStrokeWidth(2);
             paint.setStyle(Paint.Style.FILL);
             paint.setColor(Color.WHITE);
             paint.setShadowLayer(0,0,0,0xffffff);
             canvas.drawPath(path,paint);
             // 描边
             paint.setStyle(Paint.Style.STROKE);
             paint.setColor(Color.BLACK);
             canvas.drawPath(path,paint);
         }else {
             //未选中的时候
             paint.setStrokeWidth(1);
             paint.setStyle(Paint.Style.FILL);
             paint.setColor(drawColor);
             canvas.drawPath(path,paint);
             // 描边
             paint.setStyle(Paint.Style.STROKE);
             paint.setColor(Color.BLACK);
             canvas.drawPath(path,paint);
         }
    }
    public boolean isTouch(float x,float y){
        //创建一个矩形
        RectF rectF = new RectF();
        //获取到当前省份的矩形边界
        path.computeBounds(rectF, true);
        //创建一个区域对象
        Region region = new Region();
        //将path对象放入到Region区域对象中
        region.setPath(path, new Region((int)rectF.left, (int)rectF.top,(int)rectF.right, (int)rectF.bottom));
        //返回是否这个区域包含传进来的坐标
        return region.contains((int)x,(int)y);
    }
}
